﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;
using TfsCommitMonitor.Tfs;

namespace TfsCommitMonitor
{
	internal partial class AddEditProjectDialog : Form
	{
		internal AddEditProjectDialog()
		{
			InitializeComponent();
		}

		Project _project;
		internal Project Project 
		{
			get { return _project; }
		}

		private void AddEditProjectDialog_FormClosing(object sender, FormClosingEventArgs e)
		{
			//Validate

			//Add
			if (_project == null)
			{
				_project = new Project
				{
					CollectionUri = new Uri(textBox1.Text),
					ProjectPath = textBox2.Text,
					RefreshTimeInMinutes = Int32.Parse(textBox3.Text),
				};
			}
		}

		private void button3_Click(object sender, EventArgs e)
		{
			using (var picker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false, new UICredentialsProvider()))
			{
				if (picker.ShowDialog() == DialogResult.OK)
				{
					textBox1.Text = picker.SelectedTeamProjectCollection.Uri.ToString();
					textBox2.Text = picker.SelectedProjects.Single().Name;
				}
			}
		}
	}
}
